<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"	contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<html>
<head>
<script language="JavaScript" type="text/javascript" src="../scripts/jsframework.js"></script>
</head>
<script language="JavaScript">    
/**   
*根据传入的id显示右键菜单   
*/    
function showMenu(id)    
{    
    menuForm.id.value = id;    
    if("" == id)    
    {    
       popMenu(itemMenu,100,"0000");    
    }    
    else    
    {    
        popMenu(itemMenu,100,"1111");    
    }    
        event.returnValue=false;    
        event.cancelBubble=true;    
        return false;    
}    
/**   
*显示弹出菜单   
*menuDiv:右键菜单的内容   
*width:行显示的宽度   
*rowControlString:行控制字符串，0表示不显示，1表示显示，如“101”，则表示第1、3行显示，第2行不显示   
*/    
function popMenu(menuDiv,width,rowControlString)    
{    
    //创建弹出菜单    
    var pop=window.createPopup();    
    //设置弹出菜单的内容    
    pop.document.body.innerHTML=menuDiv.innerHTML;    
    var rowObjs=pop.document.body.all[0].rows;    
    //获得弹出菜单的行数    
    var rowCount=rowObjs.length;    
    //循环设置每行的属性    
    for(var i=0;i<rowObjs.length;i++)    
    {    
        //如果设置该行不显示，则行数减一    
        var hide=rowControlString.charAt(i)!='1';    
        if(hide){    
            rowCount--;    
        }    
        //设置是否显示该行    
        rowObjs[i].style.display=(hide)?"none":"";    
        //设置鼠标滑入该行时的效果    
        rowObjs[i].cells[0].onmouseover=function()    
        {    
            this.style.background="#aec3de";    
            this.style.color="red";    
        }    
        //设置鼠标滑出该行时的效果    
        rowObjs[i].cells[0].onmouseout=function(){    
            this.style.background="#5cb4dd";    
            this.style.color="#000000";    
        }    
    }    
    //屏蔽菜单的菜单    
    pop.document.oncontextmenu=function()    
    {    
            return false;    
    }    
    //选择右键菜单的一项后，菜单隐藏    
    pop.document.onclick=function()    
    {    
            pop.hide();    
    }    
    //显示菜单    
    pop.show(event.clientX-1,event.clientY,width,rowCount*25,document.body);    
    return true;    
}    
function addNode()    
{    
   var departId = menuForm.id.value;
   var str =/[a-zA-Z]\d+/;
   if(str.test(departId)){
   window.location="../TbDepartServlet?method=showadd&parDepart="+menuForm.id.value;
   }
}    
function updateNode()    
{    
       var departId = menuForm.id.value;
       var str =/[a-zA-Z]\d+/;
       if(str.test(departId)){
           if(departId.substr(0,1)!="C"){
        	   window.location="../TbDepartServlet?method=listById&departId="+menuForm.id.value;
           }
    	
       }
}    
function delNode()    
{    
    if(confirm("此群组下对应的联系人将一起删除,您确定要删除吗?"))window.location="../TbDepartServlet?method=del&delIds="+menuForm.id.value;
}    
function newContact()    
{    
	 window.location="../TbContactServlet?method=showadd&parDepartId="+menuForm.id.value;   
}    
/**
 * typeId:区分是公司还是部门
 *是公司或部门的ID
 */
function clickMenu(typeId,id)    
{    
    alert("you click a menu!");    
}    
</script> 
<body oncontextmenu = "showMenu('')">
<form name = "menuForm">    
		 <!--隐藏框，用来保存选择的菜单的id值-->    
		 <input type = "hidden" name = "id" value = "">    
		<table><tr><td>    
		<div class="dtree">    
	<script>
	var data = {};
	data['-1_1'] = 'text: 通讯录;';
	${sessionScope.result};
	
	Using("System.Web.UI.WebControls.MzTreeView");
	var a = new MzTreeView();
	
	a.dataSource = data;

	a.rootId="-1";


	a.autoSort = true;
	a.useCheckbox = true;
	a.canOperate = true;
	document.write(a.render());
	a.expandLevel(1);
</script>
</div>
</td>
</tr>
</table>
</form>

<!-- 右键开始 -->    
<div id="itemMenu" style="display:none">    
  <table border="1" width="100%" bgcolor="#D0D0D0"  cellspacing="0">    
    <tr>    
      <td style="cursor:hand;border:outset 1;font-size:12px" align="left" onclick="parent.addNode()">新增群组</td>    
    </tr>    
  
    <tr>    
      <td style="cursor:hand;border:outset 1;font-size:12px" align="left" onclick="parent.updateNode()">修改群组</td>    
    </tr>    
    <tr>    
      <td style="cursor:hand;border:outset 1;font-size:12px" align="left" onclick="parent.delNode()">删除群组</td>    
    </tr>    
  
    <tr>    
      <td style="cursor:hand;border:outset 1;font-size:12px" align="left" onclick="parent.newContact()">新增联系人</td>    
    </tr>    
  </table>    
</div>    
<!-- 右键结束 -->   
</body>
</html>
